package com.veer.shop.controller.admin;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.veer.shop.annotation.ApiControllerLog;
import com.veer.shop.annotation.ApiSecured;
import com.veer.shop.config.ApiUrlConfig;
import com.veer.shop.param.MaterialCategoryParam;
import com.veer.shop.pojo.MaterialCategory;
import com.veer.shop.pojo.ResponseData;
import com.veer.shop.service.impl.admin.MaterialCategoryServiceImpl;

/**
 * 系统素材分类管理  控制器
 * 
 * @author WangBin
 * 2020年11月08日-下午5:52:04
 */
@RestController
public class MaterialCategoriesController {
	
	@Autowired
	private MaterialCategoryServiceImpl materialCategoryServiceImpl;
	
	/**
	 * 获取素材分类列表
	 */
	@ApiSecured
	@ApiControllerLog(description = "获取素材分类列表")
	@RequestMapping( path = ApiUrlConfig.API_MATERIAL_CATEGORY_LIST_URL, method = RequestMethod.GET)
	public ResponseData<?> getList(@RequestBody(required = false) MaterialCategoryParam param, @RequestParam(name = "page_no", defaultValue = "1", required = false) int pageNo, @RequestParam(name = "page_size", defaultValue = "20", required = false)int pageSize)
	{
		return materialCategoryServiceImpl.getList(param, pageNo, pageSize);
	}
	
	/**
	 * 上传|修改素材分类
	 */
	@ApiSecured
	@ApiControllerLog(description = "上传|修改素材分类")
	@RequestMapping( path = ApiUrlConfig.API_MATERIALS_UPDATE_URL, method = RequestMethod.POST)
	public ResponseData<?> update(@RequestBody MaterialCategory category)
	{
		return materialCategoryServiceImpl.update(category);
	}
	
	/**
	 * 删除分类素材
	 */
	@ApiSecured
	@ApiControllerLog(description = "删除素材分类")
	@RequestMapping( path = ApiUrlConfig.API_MATERIALS_DELETE_URL, method = RequestMethod.POST)
	public ResponseData<?> delete(@RequestParam(name = "category_id", defaultValue = "") String id)
	{
		return materialCategoryServiceImpl.delete(id);
	}
	
	/**
	 * 素材分类详情
	 */
	@ApiSecured
	@ApiControllerLog(description = "素材分类详情")
	@RequestMapping( path = ApiUrlConfig.API_MATERIALS_GET_URL, method = RequestMethod.GET)
	public ResponseData<?> get(@RequestParam(name = "category_id", defaultValue = "") int id)
	{
		return materialCategoryServiceImpl.get(id);
	}
}
